<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$this->model('member')->up_tixianfee();
if($_RQ['op']=='get'){
	$tixianset=$this->plugin_setting('tixianset');
	$tixianset['up_feerate']=$tixianset['up_feerate']?:1;
	$tixianset['up_rate']=$tixianset['up_rate']?:5;
	$tixianset['man_fee']=$tixianset['man_fee']?:100;
	$up_type=$tixianset['up_type']?:3;
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$return['typetitle']=$this->gift_type[$up_type];
	$return['allmoney']=$member['credit'.$up_type];
	$tinum=intval($return['allmoney']/$tixianset['man_fee']);
	$tixianfees=array();
	for($i=1;$i<=$tinum;$i++){
		$tixianfees[]=$tixianset['man_fee']*$i;
	}
	$return['man_fee']=$tixianset['man_fee'];
	$return['tixianfees']=$tixianfees;
	$return['fzallmoney']=$member['credit'.$up_type.'_fz'];
	//待释放数量大于提现记录剩余的
	$fzlogfee=pdo_getsum('jy_newping_fzlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'fee');
	if($return['fzallmoney']>$fzlogfee){
		$fee=$return['fzallmoney']-$fzlogfee;
		if($fee>0){
			model('core/member')->member_credit($_SESSION['uid'],'credit'.$up_type,$fee,true,'jy_newping','释放回提');
			model('core/member')->member_credit($_SESSION['uid'],'credit'.$up_type.'_fz',$fee,false,'jy_newping','释放回提');
		}
		$return['fzallmoney'] -=$fee;
		$return['allmoney'] +=$fee;
	}
	$return['member']=$member;
	$tips=$return['typetitle'].'满《'.$tixianset['man_fee'].'》时,才可以提现释放，提现后，每天可以释放['.$tixianset['up_rate'].'%]到余额，然后余额可以随时提现。注意：每推荐1人参与拼团，立即释放['.$tixianset['up_jiarate'].'%]到余额。';
	$return['tips']=$tips;
	$return['is_open']=$tixianset['is_open'];
	$return['open_upbaofee']=$tixianset['open_upbaofee'];
	$return['params']['type']=$_RQ['type']?:2;
	$return['post']=array();
	set_html('title','我的任务');
	exi($return);
}
if($_RQ['op']=='post'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$tixianset=$this->plugin_setting('tixianset');
	if(!$tixianset['is_open']){
		exi('系统未开启虚拟提现！','erroe');
	}
	$tixianset['up_feerate']=$tixianset['up_feerate']?:1;
	$tixianset['up_rate']=$tixianset['up_rate']?:5;
	$tixianset['man_fee']=$tixianset['man_fee']?:100;
	$up_type=$tixianset['up_type']?:3;
	$post=get_postdata();
	if(!$post['fee']){
		exi('请选择要兑换的额度！','erroe');
	}
	if($member['credit'.$up_type]<$post['fee']){
		exi('当前余额不足，兑换失败！','erroe');
	}
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$up_type,$post['fee'],false,'jy_newping','虚拟币冻结');
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$up_type.'_fz',$post['fee'],true,'jy_newping','虚拟币冻结用于释放');		
	$ratefee=intval($post['fee']/100);
	$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'msg'=>'提现虚拟币用于释放',
			'fee'=>$post['fee'],
			'up_ratefee'=>$tixianset['up_rate']*$ratefee,
			'up_jiaratefee'=>$tixianset['up_jiarate']*$ratefee,
			'createtime'=>TIMESTAMP
	);
	pdo_insert('jy_newping_fzlog',$insert);
	exi('兑换成功！');
}
if($_RQ['op']=='baofee'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$tixianset=$this->plugin_setting('tixianset');
	if(!$tixianset['open_upbaofee']){
		exi('系统未开启虚拟提现保证金！','erroe');
	}
	$tixianset['up_feerate']=$tixianset['up_feerate']?:1;
	$tixianset['up_rate']=$tixianset['up_rate']?:5;
	$tixianset['man_fee']=$tixianset['man_fee']?:100;
	$up_type=$tixianset['up_type']?:3;
	$post=get_postdata();
	if(!$post['fee']){
		exi('请选择要兑换的额度！','erroe');
	}
	if($member['credit'.$up_type]<$post['fee']){
		exi('当前余额不足，兑换失败！','erroe');
	}
	$upfee=intval($post['fee']/$tixianset['up_feerate']);	
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$up_type,$post['fee'],false,'jy_newping','虚拟币兑换保证金');
	$this->model('member')->recharge($_SESSION['uid'],$upfee,0,'充值保证金');
	exi('兑换保证金成功！');
}
if($_RQ['op']=='fenlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'type'=>3);
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('core_credit_log',$params,array($pindex,$psize),$total,array('id','type','is_add','fee','remark','createtime'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			$item['typetitle']=$credit_types[$item['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}